//
// Created by liuping on 2018/7/15.
//
#include "tcp_client.h"
#include <unistd.h>

class Client : public MyTcpClient {
public:
    Client(const InetAddress& serverAddr):MyTcpClient(serverAddr){}
    void OnConnect() override {
        Send("hello world");
    }

    void OnConnectClose() override {
        LOG_INFO << "connect close |||";
    };

    int OnMessage(std::string &&data) override {
        LOG_INFO << data; // recv "hello world"
        // DisConnect();
        return data.size();
    }
};

int main() {
    //在命令行启动一个echo服务器: ncat -l 2000 --keep-open --exec /bin/cat
    auto server_addr = InetAddress("127.0.0.1", 2000);
    Client client(server_addr);
    client.Connect();
    client.Loop(); // 直到连接断开才返回
}
